package com.zzl.ssm.dao;


import com.zzl.ssm.domain.Product;
import com.zzl.ssm.domain.Role;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

public interface IProductDao {

    //根据id查询产品
    @Select("select * from product where id=#{id}")
    public Product findById(String id) throws Exception;

    //查询所有的产品信息
    @Select("select * from product")
    public List<Product> findAll() throws Exception;

    @Insert("insert into product(productNum,productName,cityName,departureTime,productPrice,productDesc,productStatus) values(#{productNum},#{productName},#{cityName},#{departureTime},#{productPrice},#{productDesc},#{productStatus})")
    void save(Product product);

    @Select("select * from role where id in( select roleId from user_role where userId=#{userId})")
    @Results(
            {
                    @Result(id = true, column = "id", property = "id"),
                    @Result(column = "roleName", property = "roleName"),
                    @Result(column = "roleDesc", property = "roleDesc"),
                    @Result(column = "id", property = "permissions", javaType = List.class, many = @Many(select = "com.zzl.ssm .dao.IPermissionDao.findByRoleId"))
            })
    public List<Role> findRoleByUserId(Long userId);
}
